Skip to content

Comments

swev-id: pytest-dev__pytest-6202 | Preserve '.[' in long report headlines (remove getmodpath sanitization)#23

Open
rowan-stein wants to merge 1 commit intopytest-dev__pytest-6202from
fix-6202-preserve-dot-bracket
Open

swev-id: pytest-dev__pytest-6202 | Preserve '.[' in long report headlines (remove getmodpath sanitization)#23
rowan-stein wants to merge 1 commit intopytest-dev__pytest-6202from
fix-6202-preserve-dot-bracket

Conversation

@rowan-stein
Copy link
Collaborator

Fixes #22

Summary

  • Long failure headlines mutated param ids containing the substring ".[" (e.g., "..[" became ".["), breaking readability and some tooling that parses pytest output.

Root cause

  • src/_pytest/python.py (PyobjMixin.getmodpath) returned s.replace(".[", "["). This was originally to avoid test_gen.[0] names from yield-based tests (removed in pytest 4.0). It now corrupts legitimate ids.

Change

  • Return the assembled modpath string unchanged.
  • Add a regression test to ensure headlines preserve param ids containing ..[ sequences.

Reproduction steps

  1. Create bug.py:
import pytest

@pytest.mark.parametrize("a", ["..["])
def test_boo(a):
    assert False
  1. Run: pytest -vv bug.py
  2. Before this fix, failure headline showed test_boo[.[] instead of test_boo[..[].

Observed failure (before fix)

bug.py F                                                                 [100%]

=================================== FAILURES ===================================
_________________________________ test_boo[.[] _________________________________

a = '..['

    @pytest.mark.parametrize("a",["..["])
    def test_boo(a):
>       assert 0
E       assert 0

bug.py:6: AssertionError
============================== 1 failed in 0.06s ===============================

Tests

  • New test testing/test_headline_modpath_param_id.py which runs a failing parametrized test with id a..[b] and asserts the -vv output includes test_boo[a..[b]] unchanged.

Notes

  • This change does not affect nodeid semantics; it only preserves the headline/domain string. Yield tests are gone, so the previous sanitization is obsolete.
  • Per instructions: not triggering CI here.

…anged; add regression test for param id with '..[' (#22)
@rowan-stein rowan-stein requested a review from a team December 25, 2025 20:45
Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good—removing the obsolete sanitization restores the expected headline text, and the new regression test captures the failure case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants